package com.example.neusoft.a16110100126yttordering.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.example.neusoft.a16110100126yttordering.R;
import com.example.neusoft.a16110100126yttordering.activities.FoodListActivity;
import com.example.neusoft.a16110100126yttordering.bean.CollectStatus;
import com.example.neusoft.a16110100126yttordering.bean.Shop;
import com.example.neusoft.a16110100126yttordering.common.Constants;
import com.squareup.picasso.Picasso;


import java.util.List;

public class ShopAdapter extends RecyclerViewAdapter<ShopAdapter.ShopViewHolder> {

    private List<CollectStatus>list;

    public ShopAdapter(Context context,List data,List<CollectStatus> collect,int layoutResource){
        super(context,data,layoutResource);
        this.list=collect;
    }
    @Override
    public void onBindViewHolder(@NonNull ShopAdapter.ShopViewHolder shopViewHolder, int i) {
        final Shop shop=(Shop) data.get(i);
//        final CollectStatus collectStatus=(CollectStatus)list.get(i);
        System.out.println("----stt---zhenkeai"+shop.getShop_id());
//        System.out.println("----+++stt-520"+collectStatus.getCollect_id());
//            System.out.println("+++stt++++shishadiao"+list.get(i));
            for(int li=0;li<list.size();++li){
                CollectStatus collectStatus=(CollectStatus)list.get(li);
                if(collectStatus.getShop_id()==shop.getShop_id()){
                    shopViewHolder.image_collect.setImageDrawable(context.getResources().getDrawable( R.drawable.ic_love1));
                    System.out.println("-------ytt---dszbyttwly----ywndwlkkm----");
                }
            }
//            if((CollectStatus)(list.get(li)).getShop_id()==1){
//
//            }

        shopViewHolder.res_name.setText(shop.getShopname());
        shopViewHolder.res_address.setText(shop.getAddress());
        shopViewHolder.res_bar.setRating(shop.getLevel());
        Picasso.get().load(Constants.BASE_URL+shop.getPic()).into(shopViewHolder.image);
        shopViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, FoodListActivity.class);
                intent.putExtra("shop_id",shop.getShop_id());
                intent.putExtra("shop_name",shop.getShopname());
                intent.putExtra("shop_pic",shop.getPic());

                context.startActivity(intent);
            }
        });

    }


    public static class ShopViewHolder extends RecyclerView.ViewHolder{
        RatingBar res_bar;
        TextView res_name,res_address;
        ImageView image,image_collect;
        public ShopViewHolder(@NonNull View itemView) {
            super(itemView);
            res_name=itemView.findViewById(R.id.textView4);
            res_bar=itemView.findViewById(R.id.ratingBar1);
            res_address=itemView.findViewById(R.id.textView9);
            image=itemView.findViewById(R.id.imageView9);
            image_collect=itemView.findViewById(R.id.imageView21);

        }
    }



}

